document | NN 2 IE 3 DOM 1 | ||||
The document object represents both the content viewed in the browser window or frame and the other content of the HTML file loaded into the window or frame. Thus, all information from the HEAD portion of the file is also part of the document object. All references to elements must include a reference to the document object. The document object has no name other than its hard-wired object name: document. | |||||
Object Model Reference
|
activeElement | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Reference to the object that currently has focus in the document. To learn more about the object, you'll need to examine the object's name or other properties. Because buttons and other elements do not receive focus on the Macintosh, the returned value of this property may vary with operating system. | |||
Examplevar currObj = document.activeElement | |||
Value Document object reference. | |||
|
alinkColor | NN 2 IE 3 DOM n/a | ||
Read/Write (IE) | |||
Color of a hypertext link as it is being clicked. The color is applied to the link text or border around an image or object embedded within an A element. See also linkColor and vlinkColor properties for unvisited and visited link colors. Internet Explorer 4 and the DOM have a parallel aLink property of the BODY object. Dynamically changed values for alinkColor are not reflected on the page in Navigator. | |||
Exampledocument.alinkColor = "green" | |||
Value A hexadecimal triplet or plain-language color name. |
|||
|
bgColor | NN 2 IE 3 DOM n/a | ||
Read/Write | |||
Background color of the element. This color setting is not reflected in the style sheet backgroundColor property except for Navigator LAYER objects. Even if the BGCOLOR attribute or bgColor property is set with a plain-language color name, the returned value is always a hexadecimal triplet. Setting the bgColor property of a document in Navigator 2 or 3 for Macintosh or Unix does not properly redraw the window. Window content is obscured by the new color on those platforms. | |||
Exampledocument.bgColor = "yellow" | |||
Value A hexadecimal triplet or plain-language color name. |
|||
|
body | NN n/a IE 4 DOM 1 | ||
Read-only | |||
Returns a reference to the BODY object defined by the BODY element within the document. This property is used as a gateway to the BODY object's properties. | |||
Exampledocument.body.leftMargin = 15 | |||
Value Object reference. | |||
|
charset | NN n/a IE 4 DOM n/a | ||
Read/Write | |||
Character encoding of the document's content. | |||
Exampleif (document.charset == "csISO5427Cyrillic") { } | |||
Value Case-insensitive alias from the character set registry ( | |||
|
defaultCharset | NN n/a IE 4 DOM n/a | ||
Read/Write | |||
Character encoding of the content of the document. | |||
Exampledocument.defaultCharset = "csISO5427Cyrillic " | |||
Value Case-insensitive alias from the character set registry ( | |||
|
domain | NN 3 IE 4 DOM n/a | ||
Read/Write | |||
The hostname of the server that served up the document. If documents from different servers on the same domain must exchange content with each other, the domain properties of both documents must be set to the same domain to avoid security restrictions. Normally, if the hosts don't match, JavaScript disallows access to the other document's form data. This property allows, for example, a page from the www server to communicate with a page served up by a secure server. | |||
Exampledocument.domain = "megaCorp.com" | |||
Value String of the domain name that two documents have in common (exclusive of the server name). | |||
|
expando | NN n/a IE 4 DOM n/a | ||
Read/Write | |||
Whether scripts in the current document allow the creation and use of custom properties assigned to the document object. The extensible nature of JavaScript allows scripters to create a new object property merely by assigning a value to it (as in document.stooge = "Curly"). This also means the document accepts incorrectly spelled property assignments, such as forgetting to set a middle letter of a long property name to uppercase (marginLeftColor). Such assignments are accepted without question, but the desired result is nowhere to be seen. If you don't intend to create custom properties, consider setting document.expando to false in an opening script statement as you author a page. This could help prevent spelling errors from causing bugs. The setting affects only scripts in the current document. | |||
Exampledocument.expando = false | |||
Value Boolean value: true | false. | |||
|
fgColor | NN 2 IE 3 DOM n/a | ||
Read/Write | |||
The foreground (text) color for the document. While you can change this property in Navigator, the text does not change dynamically in response (at least through Version 4). | |||
Exampledocument.fgColor = "darkred" | |||
Value A hexadecimal triplet or plain-language color name. |
|||
|
lastModified | NN 2 IE 3 DOM n/a | ||
Read-only | |||
The date (as a string) on which the server says the document file was last modified. Some servers don't supply this information at all or correctly. | |||
Exampledocument.write(document.lastModified) | |||
Value String representation of a date. | |||
|
linkColor | NN 2 IE 3 DOM n/a | ||
Read/Write | |||
The color of a hypertext link that has not been visited (that is, the URL of the link is not in the browser's cache). This is one of three states for a link: unvisited, activated, and visited. The color is applied to the link text or border around an image or object embedded within an A element. Changes to this property do not dynamically change the link color in Navigator 4 or earlier. In Internet Explorer 4, this property has the same effect as setting the BODY object's link property. | |||
Exampledocument.link Color= "#00FF00" | |||
Value A hexadecimal triplet or plain-language color name. |
|||
|
location | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The URL of the current document. This property was deprecated in Navigator starting with Version 3. Navigator prefers the document.URL property to reflect this value. To navigate to another page, you should assign a URL to the location.href property. | |||
Exampledocument.location = "products/widget33.html" | |||
Value A full or relative URL as a string. | |||
|
parentWindow | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Returns a reference to the window object (which may be a frame in a frameset) that contains the current document. You can use this reference to access the window's properties and methods directly. The returned value is the same as the window reference from the document. | |||
Examplevar siblingCount = document.parentWindow.frames.length | |||
Value Element object reference. | |||
|
readyState | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Returns the current download status of the document content. If a script (especially one initiated by a user event) can perform some actions while the document is still loading, but must avoid other actions until the entire page has loaded, this property provides intermediate information about the loading process. You would use its value in condition tests. The value of this property changes during loading as the loading state changes. Each change of the property value fires an onReadyStateChange event. | |||
Exampleif (document.readyState == "loading") { } | |||
Value One of the following values (as strings): complete | interactive | loading | uninitialized. Some elements may allow the user to interact with partial content, in which case the property may return interactive until all loading has completed. | |||
|
referrer | NN 2 IE 3 DOM 1 | ||
Read-only | |||
Returns a string of the URL of the page from which the current page was accessed, provided the original page had a link to the current page. Many server logs capture this information as well. Scripts can see whether the visitor reached the current document from specific origins and perhaps present slightly different content on the page accordingly. If the visitor arrived by another method, such as typing the document URL into a browser dialog or by selecting a bookmark, the referrer property returns an empty string. | |||
Exampleif (document.referrer) { document.write("<P>Thanks for following the link to our web site.</P>") } | |||
Value String. | |||
|
selection | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Returns a selection object. To work with text that has been selected by the user or script, you must convert the selection to a TextRange object. This is possible only in Internet Explorer for Win32. | |||
Examplevar range = document.selection.createRange( ) | |||
Value Object reference. | |||
|
title | NN 2 IE 3 DOM n/a | ||
Read/Write | |||
Unlike the title property for objects that reflect HTML elements, the document.title property refers to the content of the TITLE element defined in the HEAD portion of a document. The title content appears in the browser's titlebar to help identify the document. This is also the content that goes into a bookmark listing for the page. | |||
Exampledocument.title = "Fred\'s Home Page" | |||
Value String. | |||
|
URL | NN 3 IE 4 DOM n/a | ||
Read/Write | |||
The URL of the current document. The value is the same as location.href. Netscape deprecates the usage of the document.location property in favor of the document.URL property to avoid potential confusion (by scripters and JavaScript interpreter engines) between the location object and document.location property. To navigate to another page, it is safest (for cross-browser and backward compatibility) to assign a URL string value to the location.href property, rather than this document-centered property. | |||
Exampledocument.URL = "http://www.megacorp.com" | |||
Value Complete or relative URL as a string. | |||
|
vlinkColor | NN 2 IE 3 DOM n/a | ||
Read/Write (IE) | |||
Color of a hypertext link that has been visited recently. The color is applied to the link text or border around an image or object embedded within an A element. See also alinkColor and linkColor properties for clicked and unvisited link colors. Internet Explorer 4 and the DOM have a parallel vLink property of the BODY object. Changed values are not reflected on the page in Navigator. | |||
Exampledocument.vlinkColor = "gold" | |||
Value A hexadecimal triplet or plain-language color name. |
|||
|
captureEvents( ) | NN 4 IE n/a DOM n/a | ||
captureEvents(eventTypeList) Instructs the browser to grab events of a specific type before they reach their intended target objects. The object invoking this method must then have event handlers defined for the given event types to process the event. | |||
Returned Value None. | |||
Parameters
|
clear( ) | NN 2 IE 3 DOM n/a |
Removes the current document from the window or frame, usually in preparation to open a new stream for writing new content. The document.write( ) and document.writeln( ) methods automatically invoke this method. Many bugs with the document.clear( ) method plagued earlier browser versions. Even today, it is best to let the document writing methods handle the job for you. | |
Returned Value None. | |
Parameters None. |
close( ) | NN 2 IE 3 DOM n/a |
Closes the document writing stream to a window or frame. If a script uses document.write( ) or document.writeln( ) to generate all-new content for a window or frame, you must append a document.close( ) method to make sure the entire content is written to the document. Omitting this method may cause some content not to be written. This method also prepares the window or frame for a brand-new set of content with the next document writing method. Do not, however, use document.close( ) if you use the document writing methods to dynamically write content to a page loading from the server. | |
Returned Value None. | |
Parameters None. |
createElement( ) | NN n/a IE 4 DOM n/a | ||
createElement("tagName") Generates in memory an instance of an object associated with the tag passed as a parameter to the method. Use this method to create new AREA and OPTION elements. You may then assign property values to fill out the features of the element, such as the src property of an image object. Any new element of these types must then be added to their collections (with the add( ) method). | |||
Returned Value Object reference. | |||
Parameters
|
createStyleSheet( ) | NN n/a IE 4 DOM n/a | ||||
createStyleSheet(["url"[, index]]) Creates and adds a new style sheet for the document. This is also the method you can use to dynamically load an external style sheet after the document has already loaded. To do so, specify the URL of the external .css file as the first parameter. If you'd rather script the addition of individual style sheet rules, you can do so in the Win32 version only. Specify an empty string for the first parameter and then use the addRule( ) method for the styleSheet object for each rule you wish to dynamically add to the style sheet. | |||||
Returned Value styleSheet object reference (but null in IE 4/Macintosh, preventing further assignments of rules). | |||||
Parameters
|
elementFromPoint( ) | NN n/a IE 4 DOM n/a | ||||
elementFromPoint(x, y) Returns a reference to the object directly underneath the pixel coordinates specified by the x (horizontal) and y (vertical) parameters. For an element to be recognized, it must be capable of responding to mouse events. Also, if more than one element is positioned in the same location, the element with the highest zIndex value or, given equal zIndex values, the element that comes last in the source code order is the one returned. | |||||
Returned Value Element object reference. | |||||
Parameters
|
execCommand( ) | NN n/a IE 4 DOM n/a | ||||||
execCommand("commandName"[, UIFlag[, value]]) Available only in the Win32 platform for IE 4, the execCommand( ) method executes the named command. Most commands require that a TextRange object be created first for an insertion point. | |||||||
Returned Value Boolean value: true if command was successful; false if unsuccessful. | |||||||
Parameters
|
getSelection( ) | NN 4 IE n/a DOM n/a |
Captures the current text selection in the document. For IE, read the selection property instead. | |
Returned Value String. | |
Parameters None. |
handleEvent( ) | NN 4 IE n/a DOM n/a | ||
handleEvent(event) Instructs the object to accept and process the event whose specifications are passed as the parameter to the method. The object must have an event handler for the event type to process the event. | |||
Returned Value None. | |||
Parameters
|
open( ) | NN 2 IE 3 DOM n/a | ||||
open("MIMEType"[, "replace"]) Opens the output stream for writing to the current window or frame. If document.clear( ) has not already been invoked, it is automatically invoked in response to the document.open( ) method. Early version bugs may lead you to use document.write( ) and document.writeln( ) to take care of this method more reliably for you. | |||||
Returned Value None. | |||||
Parameters
|
queryCommandEnabled( ) | NN n/a IE 4 DOM n/a | ||
queryCommandEnabled("commandName") Whether the command can be invoked in light of the current state of the document or selection. Available only in the Win32 platform for IE 4. | |||
Returned Value Boolean value: true if enabled; false if not. | |||
Parameters
|
queryCommandIndeterm( ) | NN n/a IE 4 DOM n/a | ||
queryCommandIndeterm("commandName") Whether the command is in an indeterminate state. Available only in the Win32 platform for IE 4. | |||
Returned Value Boolean value: true | false. | |||
Parameters
|
queryCommandState( ) | NN n/a IE 4 DOM n/a | ||
queryCommandState("commandName") Determines the current state of the named command. Available only in the Win32 platform for IE 4. | |||
Returned Value true if the command has been completed; false if the command has not completed; null if the state cannot be accurately determined. | |||
Parameters
|
queryCommandSupported( ) | NN n/a IE 4 DOM n/a | ||
queryCommandSupported("commandName") Determines whether the named command is supported by the document object. Available only in the Win32 platform for IE 4. | |||
Returned Value Boolean value: true | false. | |||
Parameters
|
queryCommandText( ) | NN n/a IE 4 DOM n/a | ||
queryCommandText("commandName") Returns text associated with the command. Available only in the Win32 platform for IE 4. | |||
Returned Value String. | |||
Parameters
|
queryCommandValue( ) | NN n/a IE 4 DOM n/a | ||
queryCommandValue("commandName") Returns the value associated with the command, such as the name font of the selection. Available only in the Win32 platform for IE 4. | |||
Returned Value Depends on the command. | |||
Parameters
|
releaseEvents( ) | NN 4 IE n/a DOM n/a | ||
releaseEvents(eventTypeList) The opposite of document.captureEvents( ), this method turns off event capture at the document level for one or more specific events named in the parameter list. | |||
Returned Value None. | |||
Parameters
|
routeEvent( ) | NN 4 IE n/a DOM n/a | ||
routeEvent(event) Used inside an event handler function, this method directs Navigator to let the event pass to its intended target object. | |||
Returned Value None. | |||
Parameters
|
write( ), writeln( ) | NN 2 IE 3 DOM n/a | ||
write("string") writeln("string") When invoked as the page loads, these methods can dynamically add content to the page. When invoked after the page has loaded, a single method invocation clears the current document, opens a new output stream, and writes the content to the window or frame. A document.close( ) method is required afterward. Because the first document.write( ) or document.writeln( ) method destroys the current document, do not use two or more writing statements to create a new document. Instead load the content into one variable and pass that variable as the parameter to a single document.write( ) or document.writeln( ) method. The difference between the two methods is that document.writeln( ) adds a carriage return to the source code it writes to the document. This is not reflected in the rendered content, but can make reading the dynamic source code easier in browser versions that support dynamic content source viewing (Navigator does so as a wysiwyg: URL in the source view window). | |||
Returned Value None. | |||
Parameters
|
anchors[ ] | NN 2 IE 3 DOM 1 |
Returns an array of all anchor objects in the current document. This includes A elements that are designed as either anchors or combination anchors and links. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.anchors[index].objectPropertyOrMethod |
applets[ ] | NN 2 IE 3 DOM 1 |
Returns an array of all Java applet objects in the current document. An applet must be started and running before it is counted as an object. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.applets[index].objectPropertyOrMethod |
classes[ ] | NN 4 IE n/a DOM n/a |
Used with the JavaScript syntax of style sheets, the classes[] collection is part of a reference to a single class and the style property assigned to it. For a list of properties, see the tags object listing in this chapter. | |
Syntax[document.]classes.className.stylePropertyName |
embeds[ ] | NN n/a IE 4 DOM n/a |
Returns an array of all embedded objects (EMBED elements) in the current document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.embeds(index).objectPropertyOrMethod |
forms[ ] | NN 2 IE 3 DOM 1 |
Returns an array of all FORM objects (FORM elements) in the current document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.forms[index].objectPropertyOrMethod |
frames[ ] | NN n/a IE 4 DOM n/a |
Returns an array of all IFRAME objects (IFRAME elements) in the current document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.frames(index).objectPropertyOrMethod |
ids[ ] | NN 4 IE n/a DOM n/a |
Used with the JavaScript syntax of style sheets, the ids[] collection is part of a reference to a single ID and the style property assigned to it. For a list of properties, see the tags object listing in this chapter. | |
Syntax[document.]ids.idName.stylePropertyName |
images[ ] | NN 2 IE 3 DOM 1 |
Returns an array of all IMAGE objects (IMG elements) in the current document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.images[index].objectPropertyOrMethod |
links[ ] | NN 2 IE 3 DOM 1 |
Returns an array of all link-style objects (A elements whose HREF attributes are set, plus all AREA elements) in the current document. Items in this array are indexed (zero-based) in source code order. | |
Syntaxdocument.links[index].objectPropertyOrMethod |
plugins[ ] | NN n/a IE 4 DOM n/a |
Returns an array of all embedded objects (EMBED elements) in the current document. Items in this array are indexed (zero based) in source code order. Do not confuse this collection with the navigator.plugins collection in Netscape Navigator. | |
Syntaxdocument.plugins(index).objectPropertyOrMethod |
scripts[ ] | NN n/a IE 4 DOM n/a |
Returns an array of all SCRIPT objects (SCRIPT elements) in the current document. Each SCRIPT object may contain any number of functions. The scripts[] collection counts the number of actual <SCRIPT> tags in the document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.scripts(index).objectPropertyOrMethod |
styleSheets[ ] | NN n/a IE 4 DOM n/a |
Returns an array of all styleSheet objects in the current document. Each style object may contain any number of style sheet rules. The styleSheets[] collection counts the number of actual <STYLE> tags in the document. Items in this array are indexed (zero based) in source code order. | |
Syntaxdocument.styleSheets(index).objectPropertyOrMethod |